<!DOCTYPE html>
<html lang="en">
<head th:include="public/public_css::public_css ('发运订单主页面')"/>
<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <!--顶部查询框-->
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">

                    <div class="layui-inline">
                        <label class="layui-form-label">订单号</label>
                        <div class="layui-input-inline" style="width: 200px;">
                            <input type="text" class="layui-input" id="khddh" name="khddh" placeholder="客户订单号"/>
                        </div>
                    </div>
                    <div class="layui-inline" style="width: 200px;">
                        <label class="layui-form-label">SO编号</label>
                        <input type="text" class="layui-input" id="fybh" name="fybh" placeholder="SO编号"/>
                    </div>
                    <div class="layui-inline" style="width: 200px;">
                        <label class="layui-form-label">波次编号</label>
                        <input type="text" class="layui-input" id="bcbh" name="bcbh" placeholder="波次编号"/>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">订单类型</label>
                        <div class="layui-input-inline" style="width: 200px;">
                            <select lay-ignore="lay-ignore" class="js-data-example-ajax" id="ddSelect"
                                    name="fylx" select2 style="width: 200px"></select>
                        </div>
                    </div>

                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" onclick="queryTable(1)" id="query"
                           data-type="reload">查询</a>
                        <button type="reset"  id="chongzhi" class="layui-btn layui-btn-normal">
                            重置
                        </button>
                    </div>
                    <div class="moreSearch" style="display: none">
                        <div class="layui-inline">
                            <label class="layui-form-label">创建时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="time" id="createTime"
                                       placeholder="wms创建时间">
                            </div>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">拣货状态</label>
                            <select name="jhzt" lay-filter="aihao3">
                                <option value="">全部</option>
                                <option value="0">初始</option>
                                <option value="1">部分拣货</option>
                                <option value="2">全部拣货</option>
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">审核状态</label>
                            <select name="shzt" lay-filter="aihao1">
                                <option value="">全部</option>
                                <option value="0">未审核</option>
                                <option value="1">已审核</option>
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">波次状态</label>
                            <select name="bczt" lay-filter="aihao2">
                                <option value="">全部</option>
                                <option value="0">未加入</option>
                                <option value="1">已加入</option>
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">拆单状态</label>
                            <select name="cdzt" lay-filter="aihao5">
                                <option value="">全部</option>
                                <option value="0">未拆单</option>
                                <option value="1">已拆单</option>
                            </select>
                        </div>
                        <br/>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">装箱状态</label>
                            <select name="zxzt" lay-filter="aihao6">
                                <option value="">全部</option>
                                <option value="0">未装箱</option>
                                <option value="1">部分装箱</option>
                                <option value="2">全部装箱</option>
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">交货方式</label>
                            <select name="jhfs" lay-filter="aihao7">
                                <option value="">全部</option>
                                <option value="0">发运</option>
                                <option value="1">自提</option>
                                <option value="2">到付</option>
                            </select>
                        </div>
                        <div class="layui-inline" style="width: 200px;">
                            <label class="layui-form-label">SO状态</label>
                            <select name="fyzt" lay-filter="aihao12">
                                <option value="">全部</option>
                                <option value="0">初始</option>
                                <option value="1">部分分配</option>
                                <option value="2">全部分配</option>
                                <option value="3">部分发运</option>
                                <option value="4">全部发运</option>
                                <option value="5">订单取消</option>
                            </select>
                        </div>
                    </div>
                </form>
                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <!--导入-->
                <input type="hidden" id="testId" >
                <input type="hidden" id="tests">

                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table"></table>
                    </div>
                </section>

            </div>
        </div>
    </div>
</div>
<input hidden id="USER" th:value="${UserInfo}"/>
</body>
<style>
    .tooltip2 {
        display: inline-block;
        margin-left: 1rem;
    }
</style>
<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>

<script th:inline="javascript">
    const USER = JSON.parse($('#USER').val());
        $(function () {
        $(".moreBtn").on("click", function () {
            $(".moreSearch").toggle();
        });
    });

    function TEST() {
        console.log('测试！！！！！！！！！！！');
    }

    //
    var functions = [[${functions}]];
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate', 'tablebutton','upload'], function () {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            // 按钮引入
            tablebtn = layui.tablebutton,
            upload = layui.upload;
        //重置
        $("#chongzhi").on('click', function () {
            $('#ddSelect').html('<option value="' + '' + '">' + '' + '</option>').trigger("change");
        })
        //查询订单类型
        $('#ddSelect').select2({
            ajax: {
                url: '/zxsdwms/wmsshipmentorder/getPoLx',
                dataType: 'json',
                type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        ddlx: params.term
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    var arr = new Array();
                    if (data) {
                        for (var i = 0; i < data.length; i++) {
                            arr.push({id: data[i].id, text: data[i].ddlx});
                        }
                    }
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            language: "zh-CN",
            placeholder: '请选择订单类型',
            allowClear: true
        });
        //OA导入
        var uploadInst2 = upload.render({
            elem: '#tests' //绑定元素
            ,url: '/zxsdwms/file/upload' //上传接口
            ,exts: 'xls|xlsx'
            ,accept: 'file'
            ,done: function(res){
                console.info("res");
                console.info(res);
                //上传完毕回调
                zzpUtils.action({
                    url: "/wmsshipmentorder/importExcle",
                    data: JSON.stringify({filepath:res.filePath,type:'OA'}),
                    success: function (data) {
                        setTimeout(function () {
                            if (data.type == 'success') {
                                layer.msg(data.title + '<br>' + data.message);

                            } else {
                                layer.msg(data.title + '<br>' + data.message);
                            }
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            }

            ,error: function(){
                //请求异常回调
            }
        });
        //直销导入
        var uploadInst3 = upload.render({
            elem: '#testId' //绑定元素
            ,url: '/zxsdwms/file/upload' //上传接口
            ,exts: 'xls|xlsx'
            ,accept: 'file'
            ,done: function(res){
                console.info("res");
                console.info(res);
                //上传完毕回调
                zzpUtils.action({
                    url: "/wmsshipmentorder/importExcle",
                    data: JSON.stringify({filepath:res.filePath,type:'ZX'}),
                    success: function (data) {
                        setTimeout(function () {
                            if (data.type == 'success') {
                                layer.msg(data.title + '<br>' + data.message);

                            } else {
                                layer.msg(data.title + '<br>' + data.message);
                            }
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            }

            ,error: function(){
                //请求异常回调
            }
        });

        //初始化
        zzpUtils.webSocket.init();
        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                // 查看
                searchEvent: function (data) {
                    lookDialog(data.row);
                },
                //新增
                addEvent: function (data) {
                    add();
                },
                //编辑
                editEvent: function (data) {
                    if (data.row != undefined) {
                        editDialog(data.row.id);
                    }
                },
                /*标记暂不发货*/
                temporaryBfhEvent: function (data) {
                    if (data.row != undefined) {
                        temporaryShipments(data.row);
                    }
                },
                /*删除*/
                deleteEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        deleteClick(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            deleteClick(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*导出*/
                exportEvent: function (data) {
                    var arr = [];
                    if (data) {
                        arr.push(data.row.id);
                    } else {
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                        }
                    }
                    /*
                     * 以下是将ids和对象拼接在一起
                     * */
                    var str = zzpUtils.getFormJson($("#searchForm"));
                    var object2 = Object.assign({ids: arr}, str);
                    /*将条件查询和ids传到后台*/
                    zzpUtils.outputXslx({
                        url: "/wmsPurchaseOrder/getOutPutList",
                        data: JSON.stringify(object2)
                    });
                },
                /*审核*/
                auditEvent: function (data) {
                    console.log('执行了审核');
                    if (data.row) {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            audit(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }

                },
                //附件管理
                accessoryEvent: function (data) {
                    accessoryDialog(data.row.id);
                },
                //OA导入
                figureOut: function (data) {
                    $("#tests").show();
                    document.getElementById("tests").click();
                },
                //直销导入
                getlibrary: function (data) {
                    $("#testId").show();
                    document.getElementById("testId").click();
                },
                //修改承运商类别
                forwardingAgentEvent: function (data) {
                    forwardingAgentDialog(data.row);
                },
                //查看库存余量
                searchinventoryEvent: function (data) {
                    searchinventoryDialog(data.row);
                },
                //复制订单
                copyOrderEvent: function (data) {
                    zzpUtils.confirm("您将选择的发运订单进行复制订单的操作", function (index) {
                        $.ajax({
                            url: '/zxsdwms/wmsshipmentorder/copyOrder',
                            type: 'POST',
                            dataType: 'json',
                            contentType: 'application/json',
                            data: JSON.stringify({id: data.row.id}),
                            success: function (data) {
                                if (data.type === 'success') {
                                    layer.msg(data.message);
                                }else{
                                    layer.msg(data.message);
                                }
                            },
                            error: function (err) {

                            }
                        })
                    })
                },
                //退单重报
                returnInventoryAgainEvent: function (data) {
                    returnInventoryAgainDialog(data.row.id);
                },
                //退单
                returninventoryEvent: function (data) {
                    if (data.row.id) {
                        var ids = [];
                        ids.push(data.row.id);
                        zzpUtils.confirm("您将对选择的发运订单进行退单", function (index) {
                            $.ajax({
                                url: '/zxsdwms/wmsSplit/setTd',
                                type: 'POST',
                                dataType: 'json',
                                contentType: 'application/json',
                                data: JSON.stringify({ids: ids}),
                                success: function (data) {
                                    if (data.type === 'success') {
                                        layer.msg(data.message);
                                    }else{
                                        layer.msg(data.message);
                                    }
                                },
                                error: function (err) {

                                }
                            })
                        })
                    }
                },
                //创建波次
                createNumberEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        createNumber(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            createNumber(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //订单拆单
                orderSeparatedEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        orderSeparated(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            orderSeparated(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //取消拆单
                cancelSeparatedEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        cancelSeparated(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            cancelSeparated(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*分配*/
                allocationEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        allocation(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            allocation(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*取消分配*/
                cancelAllocationEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        cancelAllocation(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            cancelAllocation(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*拣货*/
                pickingEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        picking(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            picking(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*抵扣审核*/
                deductionAuditEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        deductionAudit(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            deductionAudit(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*借货完结*/
                borrowCargoEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        borrowCargo(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            borrowCargo(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*装箱*/
                packingEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        packing(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            packing(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                /*取消装箱*/
                cancelPackingEvent: function (data) {
                    if (data.row != undefined) {
                        var ids = [];
                        ids.push(data.row.id)
                        cancelPacking(ids);
                    } else {
                        var arr = [];
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                            cancelPacking(arr);
                        } else {
                            layer.msg("至少选择一条数据");
                        }
                    }
                },
                //查看拆单明细
                searchSeparatedDetailEvent: function (data) {
                    if (data.row) {
                        searchSeparatedDetailDialog(data.row);
                    }
                },
                /*查看分配明细*/
                searchAllocationDetailEvent: function (data) {
                    if (data.row) {
                        searchAllocationDetailDialog(data.row);
                    }
                },
                /*查看装箱明细*/
                searchPackingDetailEvent: function (data) {
                    if (data.row) {
                        searchPackingDetailDialog(data.row);
                    }
                },
                /*标记*/
                signEvent: function (data) {
                    console.log('标记');
                    var arr = [];
                    var $rows = $table.bootstrapTable('getSelections');
                    if ($rows.length > 0) {
                        arr = $.map($rows, function (row) {
                            return row.id;
                        })
                        console.log('rrrr', arr);
                        sign(arr);
                    } else {
                        layer.msg("至少选择一条数据");
                    }
                },
                /*导出*/
                exportEvent: function (data) {
                    var arr = [];
                    if (data.row != undefined) {
                        arr.push(data.row.id);
                    } else {
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length > 0) {
                            arr = $.map($rows, function (row) {
                                return row.id;
                            })
                        }
                    }
                    /*
                     * 以下是将ids和对象拼接在一起
                     * */
                    var str = zzpUtils.getFormJson($("#searchForm"));
                    var object2 = Object.assign({ids: arr}, str);
                    /*将条件查询和ids传到后台*/
                    zzpUtils.outputXslx({
                        url: "/wmsFaYunOrderMx/getOutFaYunOrderList",
                        data: JSON.stringify(object2)
                    });
                },
                //打印快递面单
                printExpressSingleEvent: function (data) {
                    if (data.row) {
                        printExpressSingle(data.row);
                    }
                },
                //打印箱标签
                printBoxLabelEvent: function (data) {
                    if (data.row) {
                        printBoxLabel(data.row);
                    }
                },
                //批量打印箱标签
                BatchPrintBoxLabelEvent: function (data) {
                    var arr = [];
                    var $rows = $table.bootstrapTable('getSelections');
                    if ($rows.length > 0) {
                        arr = $.map($rows, function (row) {
                            return row.id;
                        })
                        BatchPrintBoxLabel(arr);
                    } else {
                        layer.msg("至少选择一条数据");
                    }
                },
                //批量打印快递面单
                batchPrintExpressSingleEvent: function (data) {
                    batchPrintExpressSingleDialog();
                }

            }
        });

        //新增
        function add() {
            zzpUtils.dialog({
                title: false,
                type: 2,
                content: "/outOperation/AddShipment",
                btn: [],
                end: function () {
                    console.log('dialog关闭回调');
                    $('#table').bootstrapTable('refresh');
                }
            });
        }

        //编辑
        function editDialog(id) {
            localStorage.id = id;
            zzpUtils.dialog({
                title: "编辑采购订单头信息",
                type: 2,
                content: "/outOperation/EditShipment",
                end: function () {
                    console.log('dialog关闭回调');
                    $('#table').bootstrapTable('refresh');
                }
            });
            console.log('dialog打开');
        }

        //查看
        function lookDialog(row) {
            localStorage.id = row.id;
            localStorage.shzt = row.shzt;
            localStorage.gysid = row.gysid;
            zzpUtils.dialog({
                title: " 查看明细",
                type: 2,
                content: "/outOperation/LookDetail",
                area: ['80%', '80%']
            });
        }
        function deleteClick(ids) {
            var Ids = {ids: ids};
            zzpUtils.confirm("您将作废发运订单", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsshipmentorder/updateSfyx',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        function audit(data) {
            var ids = {ids: data};
            $.ajax({
                url: '/zxsdwms/wmsshipmentorder/updateShzt',
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(ids),
                success: function (data) {
                    if (data.type === 'success') {
                        layer.msg(data.title);
                        $('#table').bootstrapTable('refresh');
                    } else {
                        layer.msg(data.message);
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            })
        }

        function confirm() {
            var ids = [];
            var selectData = $table.bootstrapTable('getSelections');
            console.log('dddddddddddddd', selectData);
            if (selectData.length > 0) {
                selectData.forEach(function (item) {
                    ids.push(item.id);
                });
                var data = {ids: ids};
                $.ajax({
                    url: '/zxsdwms/wmsPurchaseOrder/updateZt',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(data),
                    success: function (data) {
                        layer.msg(data.title);
                        if (data.type === 'success') {
                            $('#table').bootstrapTable('refresh');
                        }
                    }
                })
            } else {
                layer.msg('请选择至少一条数据');
            }
        }

        function accessoryDialog(id) {
            zzpUtils.dialog({
                title: " 附件管理",
                type: 2,
                content: "/outOperation/accessory?id="+id,
                area: ['80%', '70%'],
                end: function () {
                    $('#table').bootstrapTable('refresh');
                }
            });
        }

        //修改承运商类别
        function forwardingAgentDialog(row) {
            localStorage.id = row.id;
            zzpUtils.dialog({
                title: "修改承运商类别",
                type: 2,
                content: "/outOperation/EditForwardingAgent",
                area: ['80%', '50%'],
                end: function () {//增加成功后刷新
                    $('#table').bootstrapTable('refresh');
                }
            })
        }

        //查看库存余量
        function searchinventoryDialog(row) {
            localStorage.id = row.id;
            zzpUtils.dialog({
                title: "查看库存余量",
                type: 2,
                content: "/outOperation/SearchInventory",
                area: ['80%', '70%']
            })
        }
        //退单重报
        function returnInventoryAgainDialog(id) {
            layer.open({
                title: '查看关联退单',
                type: 2,
                content: "/zxsdwms/outOperation/ReturnInventoryAgain",
                area: ['90%', '65%'],
                btn: ['保存', '取消'],
                btn1: function (index, layero) {
                    idex = index;
                    zzpUtils.confirm("您将对选择的发运订单进行退单", function (index) {
                        $.ajax({
                            url: '/zxsdwms/wmsSplit/setTdzt',
                            type: 'POST',
                            dataType: 'json',
                            contentType: 'application/json',
                            data: JSON.stringify({id: id}),
                            success: function (data) {
                                setTimeout(function () {
                                    layer.close(idex); //再执行关闭
                                    if (data.type == 'success') {
                                        layer.msg(data.message);
                                    } else {
                                        layer.msg(data.message);
                                    }
                                }, 500);
                            },
                            error: function (err) {
                            }
                        })
                    })
                },
                btn2: function (index, layero) {
                    layer.close(index);
                }
            })
        }

        //创建波次
        function createNumber(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行创建波次", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmswave/add',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //订单拆单
        function orderSeparated(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行订单拆单", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsSplit/split',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.message);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //取消拆单
        function cancelSeparated(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行取消拆单", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsSplit/cancel',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.message);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        function allocation(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行分配", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsdistribution/distribution',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type == 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        function cancelAllocation(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行取消分配", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsdistribution/cancelDistribution',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type == 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        function picking(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行拣货", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmspicking/pick',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        function deductionAudit(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行抵扣审核的操作", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsloading/deductible',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        function borrowCargo(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行借货完结的操作", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsshipmentorder/updateJhwjzt',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        function packing(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行装箱的操作", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsbox/boxZx',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        function cancelPacking(data) {
            var Ids = {ids: data};
            zzpUtils.confirm("您将对选择的发运订单进行取消装箱的操作", function (index) {
                $.ajax({
                    url: '/zxsdwms/wmsbox/cancelBoxZx',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(Ids),
                    success: function (data) {
                        if (data.type === 'success') {
                            layer.msg(data.title);
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(data.message);
                        }
                    }
                })
            })
        }

        //查看拆单明细
        function searchSeparatedDetailDialog(row) {
            localStorage.id = row.id;
            zzpUtils.dialog({
                title: "查看拆单明细",
                type: 2,
                content: "/outOperation/SeparatedDetail",
                area: ['80%', '70%']
            })
        }

        function searchAllocationDetailDialog(row) {
            localStorage.id = row.id;
            zzpUtils.dialog({
                title: "查看分配明细",
                type: 2,
                content: "/outOperation/AllocationDetail",
                area: ['80%', '60%']
            })
        }

        function searchPackingDetailDialog(row) {
            localStorage.id = row.id;
            zzpUtils.dialog({
                title: "查看装箱明细",
                type: 2,
                content: "/outOperation/PackingDetail",
                area: ['80%', '70%']
            })
        }

        function sign(data) {
            var ids = {ids: data};
            $.ajax({
                url: '/zxsdwms/wmsshipmentorder/updateZt',
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(ids),
                success: function (data) {
                    if (data.type === 'success') {
                        layer.msg(data.title);
                        $('#table').bootstrapTable('refresh');
                    } else {
                        layer.msg(data.message);
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            })
        }
        //打印快递面单
        function printExpressSingle(row) {
            console.log('啦啦啦');
            var ids = [];
            ids.push(row.id);
            $.ajax({
                url: '/zxsdwms/wmsreview/zxPrintByFyIds',
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify({ids: ids}),
                success: function (data) {
                    if (data.type === 'success') {
                        var contentList = data.data;
                        if (contentList.length !== 0) {
                            // 先调用方法
                            var LODOP = GetLodop();
                            // 打印名称
                            // LODOP.PRINT_INIT('打印快递面单')
                            for (var item of contentList) {
                                /* NewPage意思新的一页 如果多个数据放到for里面必须写 */
                                LODOP.NewPage()
                                // ADD_PRINT_URL 设置参数 item 最后的item是你打印的地址
                                LODOP.ADD_PRINT_URL(0, 0, 746, '100%', item)
                                LODOP.SET_PRINT_STYLEA(0, 'HOrient', 3)
                                LODOP.SET_PRINT_STYLEA(0, 'VOrient', 3)
                            }
                            LODOP.PREVIEW()
                        }
                    } else {
                        layer.msg(data.message);
                    }
                }
            })

        }

        //打印箱标签
        function printBoxLabel(row) {
            var ids = [];
            ids.push(row.id);
            var data;
            $.ajax({
                url: '/zxsdwms/wmsbox/printeZxmx',
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify({ids: ids}),
                success: function (DATA) {console.log(DATA);
                    data = DATA.rows;
                    var  LODOP = getLodop();
                    LODOP.PRINT_INIT('打印箱标签信息');
                    var index = 0;
                    var leftwidth = 10;
                    for (var s=0;s<data.length;s++) {
                        LODOP.NewPage();
                        // LODOP.ADD_PRINT_RECT(5, 15, 360, 275, 0, 1); // 画边框
                        LODOP.ADD_PRINT_TEXT(2, 93 + leftwidth, 250, 25, data[index].show_rent);
                        LODOP.SET_PRINT_STYLEA(0, 'FontName', '隶书');
                        LODOP.SET_PRINT_STYLEA(0, 'FontSize', 13);
                        LODOP.SET_PRINT_STYLEA(0, 'Bold', 1);
                        LODOP.ADD_PRINT_TEXT(31, 3 + leftwidth, 57, 20, '起始站：');
                        LODOP.ADD_PRINT_TEXT(31, 63 + leftwidth, 145, 20, data[index].ownermc);
                        LODOP.ADD_PRINT_TEXT(31, 210 + leftwidth, 57, 20, '收货人：');
                        LODOP.ADD_PRINT_TEXT(31, 276 + leftwidth, 100, 20, data[index].lxrxm);
                        LODOP.ADD_PRINT_TEXT(53, 3 + leftwidth, 57, 20, '订单号：');
                        LODOP.ADD_PRINT_TEXT(53, 63 + leftwidth, 145, 20, data[index].sobh);
                        LODOP.ADD_PRINT_TEXT(53, 210 + leftwidth, 69, 20, '联系电话：');
                        LODOP.ADD_PRINT_TEXT(53, 276 + leftwidth, 81, 20, data[index].lxrdh);
                        LODOP.ADD_PRINT_TEXT(76, 3 + leftwidth, 69, 20, '收货地址：');
                        LODOP.ADD_PRINT_TEXT(76, 67 + leftwidth, 291, 37, data[index].khdz);
                        LODOP.ADD_PRINT_TEXT(123, 3 + leftwidth, 124, 20, '散箱数量：' + data[index].sxsl);
                        LODOP.ADD_PRINT_TEXT(123, 118 + leftwidth, 104, 20, '整箱数量：' + data[index].zxsl);
                        LODOP.ADD_PRINT_TEXT(123, 220 + leftwidth, 138, 20, '当前：' + data[index].xxh + '/' + data[index].maxXxh + ' ' + data[index].zslx);
                        LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1); // 外边框
                        // LODOP.ADD_PRINT_RECT(136, 0 + leftwidth, '100mm', 111, 0, 1); // 明细边框
                        LODOP.ADD_PRINT_LINE(136, 10, 136, '102mm', 0, 1); // 横线
                        LODOP.ADD_PRINT_TEXT(138, 2 + leftwidth, 36, 20, '序号');
                        LODOP.ADD_PRINT_TEXT(138, 45 + leftwidth, 167, 20, '货品名称');
                        LODOP.ADD_PRINT_TEXT(138, 210 + leftwidth, 34, 20, '规格');
                        LODOP.ADD_PRINT_TEXT(138, 295 + leftwidth, 36, 20, '单位');
                        LODOP.ADD_PRINT_TEXT(138, 339 + leftwidth, 35, 20, '数量');
                        if (data[index].boxMx.length > 0) {
                            var height;
                            for (var mx = 0, mcx = 0; mx < data[index].boxMx.length; mx++, mcx++) {
                                var datalength = data[index].boxMx.length;
                                console.log('datalength', datalength);
                                console.log('mmmmx', mx);
                                var mcxs;
                                if (mx < 7) {
                                    height = 158;
                                    mcxs = mcx;
                                } else if (mx < 22) {
                                    height = 10;
                                    mcxs = mcx - 7;
                                } else {
                                    height = 10;
                                    mcxs = mcx - 22;
                                }
                                LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 1 + leftwidth, 37, 20, mx + 1);
                                LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 45 + leftwidth, 167, 20, data[index].boxMx[mx].goodsMc);
                                LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 200 + leftwidth, 122, 20, data[index].boxMx[mx].gg || ''); // 规格
                                LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 296 + leftwidth, 34, 20, data[index].boxMx[mx].dw || ''); // 单位
                                LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 339 + leftwidth, 48, 20, data[index].boxMx[mx].sl);
                                if (datalength < 5) {
                                    LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                } else if (datalength >= 5 && datalength < 7) {
                                    if (mx === (datalength - 1)) {
                                        console.log('分页');
                                        LODOP.NewPage();
                                        LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                        LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                    }
                                } else if (datalength >= 7 && datalength < 19) {
                                    if (mx === 6) {
                                        console.log('分页');
                                        LODOP.NewPage();
                                        LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                        LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                    }
                                } else if (datalength >= 19 && datalength < 22) {
                                    if (mx === 6 || mx === (datalength - 1)) {
                                        console.log('分页');
                                        LODOP.NewPage();
                                        LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                        if (mx === (datalength - 1)) {
                                            LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                        }
                                    }
                                } else if (datalength >= 22) {
                                    if (mx === 6 || mx === 21) {
                                        console.log('分页');
                                        LODOP.NewPage();
                                        LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                        if (mx === 21) {
                                            LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                        }
                                    }
                                }
                            }
                        }
                        LODOP.ADD_PRINT_LINE(247, 95 + leftwidth, 302, 95 + leftwidth, 0, 1); // 画竖线
                        LODOP.ADD_PRINT_TEXT(257, 1 + leftwidth, 98, 37, data[index].xx); // 箱型
                        LODOP.ADD_PRINT_TEXT(267, 1 + leftwidth, 110, 40, data[index].llzl); // 理论重量
                        LODOP.ADD_PRINT_BARCODE(250, 103 + leftwidth, 251, 49, 'Code39', data[index].xbh);
                        index++;
                    }
                    LODOP.PREVIEW();
                }
            })
        }


        //批量打印箱标签
        function BatchPrintBoxLabel(ids) {
            $.ajax({
                url: '/zxsdwms/wmsbox/printeZxmx',
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify({ids: ids}),
                success: function (DATA) {console.log(DATA);
                    data = DATA.rows;
                    var  LODOP = getLodop();
                    LODOP.PRINT_INIT('打印箱标签信息');
                    var index = 0;
                    var leftwidth = 10;
                    for (var s=0;s<data.length;s++) {
                        LODOP.NewPage();
                        // LODOP.ADD_PRINT_RECT(5, 15, 360, 275, 0, 1); // 画边框
                        LODOP.ADD_PRINT_TEXT(2, 93 + leftwidth, 250, 25, data[index].show_rent);
                        LODOP.SET_PRINT_STYLEA(0, 'FontName', '隶书');
                        LODOP.SET_PRINT_STYLEA(0, 'FontSize', 13);
                        LODOP.SET_PRINT_STYLEA(0, 'Bold', 1);
                        LODOP.ADD_PRINT_TEXT(31, 3 + leftwidth, 57, 20, '起始站：');
                        LODOP.ADD_PRINT_TEXT(31, 63 + leftwidth, 145, 20, data[index].ownermc);
                        LODOP.ADD_PRINT_TEXT(31, 210 + leftwidth, 57, 20, '收货人：');
                        LODOP.ADD_PRINT_TEXT(31, 276 + leftwidth, 100, 20, data[index].lxrxm);
                        LODOP.ADD_PRINT_TEXT(53, 3 + leftwidth, 57, 20, '订单号：');
                        LODOP.ADD_PRINT_TEXT(53, 63 + leftwidth, 145, 20, data[index].sobh);
                        LODOP.ADD_PRINT_TEXT(53, 210 + leftwidth, 69, 20, '联系电话：');
                        LODOP.ADD_PRINT_TEXT(53, 276 + leftwidth, 81, 20, data[index].lxrdh);
                        LODOP.ADD_PRINT_TEXT(76, 3 + leftwidth, 69, 20, '收货地址：');
                        LODOP.ADD_PRINT_TEXT(76, 67 + leftwidth, 291, 37, data[index].khdz);
                        LODOP.ADD_PRINT_TEXT(123, 3 + leftwidth, 124, 20, '散箱数量：' + data[index].sxsl);
                        LODOP.ADD_PRINT_TEXT(123, 118 + leftwidth, 104, 20, '整箱数量：' + data[index].zxsl);
                        LODOP.ADD_PRINT_TEXT(123, 220 + leftwidth, 138, 20, '当前：' + data[index].xxh + '/' + data[index].maxXxh + ' ' + data[index].zslx);
                        LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1); // 外边框
                        // LODOP.ADD_PRINT_RECT(136, 0 + leftwidth, '100mm', 111, 0, 1); // 明细边框
                        LODOP.ADD_PRINT_LINE(136, 10, 136, '102mm', 0, 1); // 横线
                        LODOP.ADD_PRINT_TEXT(138, 2 + leftwidth, 36, 20, '序号');
                        LODOP.ADD_PRINT_TEXT(138, 45 + leftwidth, 167, 20, '货品名称');
                        LODOP.ADD_PRINT_TEXT(138, 210 + leftwidth, 34, 20, '规格');
                        LODOP.ADD_PRINT_TEXT(138, 295 + leftwidth, 36, 20, '单位');
                        LODOP.ADD_PRINT_TEXT(138, 339 + leftwidth, 35, 20, '数量');
                        if (data[index].boxMx.length > 0) {
                            var height;
                            for (var mx = 0, mcx = 0; mx < data[index].boxMx.length; mx++, mcx++) {
                                var datalength = data[index].boxMx.length;
                                console.log('datalength', datalength);
                                console.log('mmmmx', mx);
                                var mcxs;
                                if (mx < 7) {
                                    height = 158;
                                    mcxs = mcx;
                                } else if (mx < 22) {
                                    height = 10;
                                    mcxs = mcx - 7;
                                } else {
                                    height = 10;
                                    mcxs = mcx - 22;
                                }
                                LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 1 + leftwidth, 37, 20, mx + 1);
                                LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 45 + leftwidth, 167, 20, data[index].boxMx[mx].goodsMc);
                                LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 200 + leftwidth, 122, 20, data[index].boxMx[mx].gg || ''); // 规格
                                LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 296 + leftwidth, 34, 20, data[index].boxMx[mx].dw || ''); // 单位
                                LODOP.ADD_PRINT_TEXT(height + mcxs * 20, 339 + leftwidth, 48, 20, data[index].boxMx[mx].sl);
                                if (datalength < 5) {
                                    LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                } else if (datalength >= 5 && datalength < 7) {
                                    if (mx === (datalength - 1)) {
                                        console.log('分页');
                                        LODOP.NewPage();
                                        LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                        LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                    }
                                } else if (datalength >= 7 && datalength < 19) {
                                    if (mx === 6) {
                                        console.log('分页');
                                        LODOP.NewPage();
                                        LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                        LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                    }
                                } else if (datalength >= 19 && datalength < 22) {
                                    if (mx === 6 || mx === (datalength - 1)) {
                                        console.log('分页');
                                        LODOP.NewPage();
                                        LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                        if (mx === (datalength - 1)) {
                                            LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                        }
                                    }
                                } else if (datalength >= 22) {
                                    if (mx === 6 || mx === 21) {
                                        console.log('分页');
                                        LODOP.NewPage();
                                        LODOP.ADD_PRINT_RECT(0, 0 + leftwidth, '100mm', '80mm', 0, 1);
                                        if (mx === 21) {
                                            LODOP.ADD_PRINT_LINE(246, 10, 246, '102mm', 0, 1);
                                        }
                                    }
                                }
                            }
                        }
                        LODOP.ADD_PRINT_LINE(247, 95 + leftwidth, 302, 95 + leftwidth, 0, 1); // 画竖线
                        LODOP.ADD_PRINT_TEXT(257, 1 + leftwidth, 98, 37, data[index].xx); // 箱型
                        LODOP.ADD_PRINT_TEXT(267, 1 + leftwidth, 110, 40, data[index].llzl); // 理论重量
                        LODOP.ADD_PRINT_BARCODE(250, 103 + leftwidth, 251, 49, 'Code39', data[index].xbh);
                        index++;
                    }
                    LODOP.PREVIEW();
                }
            })

        }
        //批量打印快递面单
        function batchPrintExpressSingleDialog() {
            zzpUtils.dialog({
                title: "批量打印快递面单",
                type: 2,
                area: ['90%', '90%'], //设置dialog大小，也可以不设置，
                content: "/outOperation/BatchPrintExpressSingle",
                btn: [],
            });
        }


        laydate.render({
            elem: '#createTime'
            , range: true
        });
        // 主页面table
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            isOperate: true,
            //functions: functions.tableBtn,
            url: '/wmsshipmentorder/list',
            columns: [
                {field: '', checkbox: true},
                {field: 'fybh', title: 'SO编号'},
                {field: 'khddh', title: '客户订单号'},
                {field: 'show_fylx', title: 'SO类型'},
                {field: 'khbh', title: '客户编号'},
                {field: 'khmc', title: '客户名称'},
                {field: 'show_print', title: '打印箱标签状态'},
                {field: 'lxrxm', title: '联系人',visible:false},
                {field: 'show_dpczt', title: '批次状态',visible:false},
                {field:'xlmc',title:'路线',visible:false},
                {field:'khdz','title':'客户地址',visible:false},
                {field:'show_shzt',title:'审核状态',visible:false},
                {field:'show_cdzt',title:'拆单状态',visible:false},
                {field:'zyf',title:'总运费',visible:false},
                {field:'show_zxzt',title:'装箱状态',visible:false},
                {field:'show_bczt',title:'波次状态',visible:false},
                {field:'show_jhzt',title:'拣货状态',visible:false},
                {field:'show_jhrwzt',title:'拣货任务状态',visible:false},
                {field:'cjsj',title:'wms创建时间',visible:false,
                    formatter: function (value, row, index) {
                        var sj='';
                        if(value!=null&&value!=''){
                            sj=value.substring(0,19);
                        }
                        return sj;
                    }
                },
                {field:'show_cyslb',title:'承运商类别',visible:false},
                {field:'fqbm',title:'发起部门',visible:false},
                {field:'fqr',title:'发起人',visible:false},
                {field:'show_tdzt',title:'退单状态',visible:false},
                {field:'show_thzt',title:'退货状态',visible:false},
                {field:'bcbh',title:'波次编号',visible:false},
                {field:'hpbh',title:'货品编号',visible:false},
                {field:'hpmc',title:'货品名称',visible:false},
                {field:'yxj',title:'优先级',visible:false},
                {field:'gldh',title:'关联单号',visible:false},
                {field:'s   how_jhfs',title:'交货方式',visible:false},
                {field:'show_fyzt',title:'SO状态',visible:false},
                {field:'jhfhsj',title:'计划发货时间',visible:false,
                    formatter: function (value, row, index) {
                        var sj='';
                        if(value!=null&&value!=''){
                            sj=value.substring(0,19);
                        }
                        return sj;
                    }
                },
                {field:'yqjhsj',title:'要求交货时间',visible:false,
                    formatter: function (value, row, index) {
                        var sj='';
                        if(value!=null&&value!=''){
                            sj=value.substring(0,19);
                        }
                        return sj;
                    }
                },
                {field:'khcjsj',title:'客户创建时间',visible:false,
                    formatter: function (value, row, index) {
                        var sj='';
                        if(value!=null&&value!=''){
                            sj=value.substring(0,19);
                        }
                        return sj;
                    }
                },

                {field:'hybh',title:'会员编号',visible:false},
                {field:'khdj',title:'客户等级',visible:false},
                {field:'bz',title:'备注',visible:false}

            ],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            operateFormatter: operateFormatter

        });

        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var btn = '', button = '', buttons1 = '', buttons2 = '';
            var buttons = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '">更多</a>'
                + '<div class="tooltip_templates"><span id="tool' + row.id + '">';
            var tablebtn = functions.tableBtn, tablebtns = [], tablearr = [], tablearrs = [];
            // 按钮排序
            tablebtn.forEach(function (item) {
                switch (item.event) {
                    case 'deductionAuditEvent':// 抵扣审核
                        tablearr[0] = item;
                        break;
                    case 'borrowCargoEvent': // 借货完结
                        tablearr[1] = item;
                        break;
                    case 'returninventoryEvent': // 退单
                        tablearr[2] = item;
                        break;
                    case 'returnInventoryAgainEvent': // 退单重报
                        tablearr[3] = item;
                        break;
                    case 'copyOrderEvent': // 复制订单
                        tablearr[4] = item;
                        break;
                    case 'createNumberEvent': // 创建波次
                        tablearr[5] = item;
                        break;
                    case 'orderSeparatedEvent': // 订单拆单
                        tablearr[6] = item;
                        break;
                    case 'cancelSeparatedEvent': // 取消拆单
                        tablearr[7] = item;
                        break;
                    case 'allocationEvent': // 分配
                        tablearr[8] = item;
                        break;
                    case 'cancelAllocationEvent': // 取消分配
                        tablearr[9] = item;
                        break;
                    case 'packingEvent': // 装箱
                        tablearr[10] = item;
                        break;
                    case 'cancelPackingEvent': // 取消装箱
                        tablearr[11] = item;
                        break;
                    case 'pickingEvent': // 拣货
                        tablearr[12] = item;
                        break;
                    case 'searchSeparatedDetailEvent': // 查看拆单明细
                        tablearr[13] = item;
                        break;
                    case 'searchAllocationDetailEvent': // 查看分配明细
                        tablearr[14] = item;
                        break;
                    case 'searchPackingDetailEvent': // 查看装箱明细
                        tablearr[15] = item;
                        break;
                    default:
                        tablebtns.push(item);
                }
            });
            tablearrs = tablearr.concat(tablebtns);
            for (var i = 0; i < tablearrs.length; i++) {
                var item = tablearrs[i];
                var Disable = '<button class="layui-btn layui-btn-xs layui-btn-disabled" disabled lay-event="' + item.event + '">' + item.name + '</button>';
                var Enable = '<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + item.event + '">' + item.name + '</button>';
                //更多之外
                if (item.event === 'searchEvent' || item.event === 'editEvent' || item.event === 'deleteEvent' || item.event === 'printExpressSingleEvent' || item.event === 'printBoxLabelEvent') {
                    switch (item.event) {
                        case 'editEvent':
                            if(USER.auth.indexOf('outOperation_shipment_edit')!==-1 &&row.cdzt === '0')
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;
                            break;
                        case 'deleteEvent':
                         //   buttons1 += '<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + item.event + '">' + item.name + '</button>';
                            if(USER.auth.indexOf('outOperation_shipment_disable')!==-1 &&row.cdzt === '0')
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;
                            break;
                        case 'printExpressSingleEvent'://打印快递面单
                            if((row.cyslb === '3' || row.cyslb === '6') && row.zxzt !== '0')
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;

                            break;
                        case 'printBoxLabelEvent':// 打印箱标签
                            if(row.zxzt !== '0')
                                buttons1 += Enable;
                            else
                                buttons1 += Disable;
                            break;
                        default:
                            buttons1 += Enable;
                    }
                } else {
                    //更多之内
                    switch (item.event) {
                        case 'deductionAuditEvent':// 抵扣审核
                            /*if (row.show_fylx === '抵扣')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;*/
                            break;
                        case 'borrowCargoEvent': // 借货完结
                            /*if (row.show_fylx ==='借货' && row.jhwjzt==='0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;*/
                            break;
                        case 'returnInventoryAgainEvent': // 退单重报
                            /*if ((row.fyzt ==='3' || row.fyzt==='4' || row.fyzt ==='0') && (row.thzt === '0') && (row.tdzt!=='2'))
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;*/
                            break;
                        case 'returninventoryEvent': // 退单
                            /*if (row.fyzt === '0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;*/
                            break;
                        case 'signEvent': // 标记
                            if (USER.auth.indexOf('outOperation_shipment_sign')!==-1 &&row.fyzt === '3')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'createNumberEvent': // 创建波次
                            if (USER.auth.indexOf('outOperation_shipment_create')!==-1 && row.bczt ==='0'&& row.fyzt ==='0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'orderSeparatedEvent': // 订单拆单
                            if (USER.auth.indexOf('outOperation_shipment_remove')!==-1 && row.shzt ==='1' && row.cdzt === '0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'cancelSeparatedEvent': // 取消拆单
                            console.log('cancelSeparatedEvent', USER.auth.indexOf('outOperation_shipment_cancel'));
                            console.log(123456, row.cdzt, row.fyzt)
                            if (USER.auth.indexOf('outOperation_shipment_cancel')!==-1 && row.cdzt==='1' && row.fyzt ==='0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'allocationEvent': // 分配
                            if (USER.auth.indexOf('outOperation_shipment_allot')!==-1 && row.cdzt==='1'&& row.fyzt ==='0' && row.jhrwzt ==='0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'cancelAllocationEvent': // 取消分配
                            if (USER.auth.indexOf('business_customerFile_search')!==-1 && row.jhzt ==='0'&& row.zxzt==='0' && row.fyzt !=='0' && row.jhrwzt ==='0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'packingEvent': // 装箱
                            if (USER.auth.indexOf('business_customerFile_search')!==-1 && (row.jhzt ==='0'&& row.zxzt==='0' && row.fyzt !=='0' && row.jhrwzt ==='0'))
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'cancelPackingEvent': // 取消装箱
                            if (USER.auth.indexOf('business_customerFile_search')!==-1 && (row.zxzt ==='1' || row.zxzt === '2') && row.jhrwzt ==='0' && row.jhzt ==='0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'pickingEvent': // 拣货
                            if (USER.auth.indexOf('outOperation_shipment_picking')!==-1 && (row.fyzt==='1'|| row.fyzt==='2') && row.jhrwzt !=='2' && row.jhzt ==='0')
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'searchSeparatedDetailEvent': // 查看拆单明细
                            if (USER.auth.indexOf('outOperation_shipment_splitsingledetailed')!==-1)
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        case 'searchAllocationDetailEvent': // 查看分配明细
                            if (USER.auth.indexOf('outOperation_shipment_allotdetailed')!==-1)
                                buttons2 += Enable;
                            else
                                buttons2 += Disable;
                            break;
                        default:
                            buttons2 += Enable;
                    }
                }
            }
            button += buttons1;
            button += buttons;
            button += buttons2;
            button += '</span></div>';
            return button;
        }

//        $(".inline-search-btn").on('click',function () {
//            zzpUtils.refreshTable("#table");
//        })

        //搜索按钮
        window.queryTable = function (val) {
            var formdata = $("form").serializeArray();
            $("#flSelect").select2("val", " ");
            var Datas = {};
            var cjsjstart = '', cjsjend = '';
            formdata.forEach(function (item) {
                Datas[item.name] = item.value;
            });
            if (Datas.time) {
                var start = Datas.time.substring(0, 10);
                var end = Datas.time.substring(12);
                console.log('timestart', start, end);
                var timestart = new Date(start);
                cjsjstart = timestart.getTime();
                var timeend = new Date(end);
                cjsjend = timeend.getTime();
            }
            var DATA = {};
            for (var key in Datas) {
                if (key !== 'time') {
                    if (val === 1) {
                        DATA[key] = Datas[key];
                    } else {
                        DATA[key] = "";
                    }
                }
            }
            if (val === 1) {
                DATA.cjsj_start = cjsjstart;
                DATA.cjsj_end = cjsjend;
            } else {
                DATA.cjsj_start = "";
                DATA.cjsj_end = "";
            }
            DATA.page = 1;
            DATA.rows = 10;
            console.log('DDDDDD', DATA);
            $('#table').bootstrapTable('refresh', {
                query: DATA
            })
        }

    });
</script>

</html>